home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Conversion / Convert_RTF / Source / FontEntry.m < prev    next >
Text File  |  1993-10-02  |  12KB  |  338 lines

  1. /***********************************************************************\
  2. Font Entry class for Convert RTF which converts between Mac and NeXT rtf formats.
  3. Copyright (C) 1993 David John Burrowes
  4.  
  5. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version.
  6.  
  7. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  8.  
  9. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  10.  
  11. The author, David John Burrowes, can be reached at:
  12.     davidjohn@kira.net.netcom.com
  13.     David John Burrowes
  14.     1926 Ivy #10
  15.     San Mateo, CA 94403-1367
  16. \***********************************************************************/
  17.  
  18. #include "FontEntry.h"
  19. #include "rtfToken.h"
  20. #include <stdio.h>
  21. #include <string.h>
  22. @implementation  FontEntry
  23.  
  24. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  25. //    Routine:        init: 
  26. //    Parameters:    none
  27. //    Returns:        self
  28. //    Stores:        none
  29. //    Description:
  30. //        This initalizes the instance so that it's values are all 0, save FontName which is
  31. //        set to an empty cstring.
  32. //    Bugs
  33. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  34. - init
  35. {
  36.     [super   init];
  37.     FontNumber = 0;
  38.     FontType = NullInstance;
  39.     FontName = NewCString(0);
  40.     Count = 0;
  41.     Convert = NoConversion;
  42.     return self;
  43. }
  44.  
  45.  
  46. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  47. //    Routine:        free:
  48. //    Parameters:    none
  49. //    Returns:        self
  50. //    Stores:        none
  51. //    Description:
  52. //        This disposes of the instance, freeing the string and the type if appropriate.
  53. //    Bugs
  54. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  55. - free
  56. {
  57.     if (FontType != NullInstance)
  58.         [FontType   free];
  59.     FreeCString(FontName);
  60.     return [super   free];
  61. }
  62.  
  63.  
  64. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  65. //    Routine:        IncrementCount
  66. //    Parameters:    none
  67. //    Returns:        self
  68. //    Stores:        none
  69. //    Description:
  70. //        This adds one to the instance's count variable
  71. //    Bugs
  72. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  73. - IncrementCount
  74. {
  75.     Count ++;
  76.     return self;
  77. }
  78.  
  79.  
  80. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  81. //    Routine:        DecrementCount
  82. //    Parameters:    none
  83. //    Returns:        self
  84. //    Stores:        none
  85. //    Description:
  86. //        This subtracts one to the instance's count variable
  87. //    Bugs
  88. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  89. - DecrementCount
  90. {
  91.     Count --;
  92.     return self;
  93. }
  94.  
  95.  
  96. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  97. //    Routine:        GetCount
  98. //    Parameters:    none
  99. //    Returns:        An Integer representing the current count.
  100. //    Stores:        none
  101. //    Description:
  102. //        This returns an integer that shows the current count value.
  103. //    Bugs
  104. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  105. - (Integer) GetCount;
  106. {
  107.     return Count;
  108. }
  109.  
  110.  
  111. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  112. //    Routine:        SetCount
  113. //    Parameters:    an integer
  114. //    Returns:        self
  115. //    Stores:        none
  116. //    Description:
  117. //        This replaces the current value of the count variable with whatever the caller has
  118. //        specified here.  This should be a rare thing to call.
  119. //    Bugs
  120. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  121. - SetCount: (Integer) NewCount
  122. {
  123.     Count = NewCount;
  124.     return self;
  125. }
  126.  
  127.  
  128. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  129. //    Routine:        SetNumber:
  130. //    Parameters:    an integer
  131. //    Returns:        self
  132. //    Stores:        none
  133. //    Description:
  134. //        This replaces the current value of the Font number value with the one the caller has
  135. //        specified.
  136. //    Bugs
  137. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  138. - SetNumber: (Integer) NewNumber
  139. {
  140.     FontNumber = NewNumber;
  141.     return self;
  142. }
  143.  
  144.  
  145. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  146. //    Routine:        GetNumber
  147. //    Parameters:    none
  148. //    Returns:        an integer
  149. //    Stores:        none
  150. //    Description:
  151. //        Returns the current value of the font number to the caller.
  152. //    Bugs
  153. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  154. - (Integer) GetNumber
  155. {
  156.     return FontNumber;
  157. }
  158.  
  159.  
  160. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  161. //    Routine:        SetFontType:
  162. //    Parameters:    An instance value
  163. //    Returns:        self
  164. //    Stores:        none
  165. //    Description:
  166. //        This replaces any existing font type value in the instance with the one specified by
  167. //        the caller.  It does NOT make a copy.
  168. //    Bugs
  169. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  170. - SetFontType: theType
  171. {
  172.     if (FontType != NullInstance)
  173.         [FontType   free];
  174.     FontType = theType;
  175.     return self;
  176. }
  177.  
  178.  
  179. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  180. //    Routine:        GetFontType
  181. //    Parameters:    none
  182. //    Returns:        An Instance
  183. //    Stores:        none
  184. //    Description:
  185. //        Returns the current value of the font type instance to the caller.  It does this
  186. //        by making a new token, and copying the values over.
  187. //    Bugs
  188. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  189. - (Instance) GetFontType
  190. {
  191.     Instance        tokenCopy    = [[rtfToken   alloc] initTokenOfType: [FontType GetType]];
  192.     CString        stupidMemLeak;
  193.     
  194.     stupidMemLeak = [FontType GetName];
  195.     [tokenCopy  SetTokenName:  stupidMemLeak];
  196.     FreeCString(stupidMemLeak);
  197.     if ( [FontType HasValue] ==  YES)
  198.         [tokenCopy  SetTokenValue:  [FontType GetValue]];
  199.     
  200.     return tokenCopy;
  201. }
  202.  
  203.  
  204. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  205. //    Routine:        SetConversion:
  206. //    Parameters:    An enumerated value
  207. //    Returns:        self
  208. //    Stores:        none
  209. //    Description:
  210. //        When called, this will set the conversion flag in the instance to the value specified by
  211. //        the caller.
  212. //    Bugs
  213. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  214. - SetConversion: (ConvertTypes) newConvert
  215. {
  216.     Convert = newConvert;
  217.     return self;
  218. }
  219.  
  220.  
  221. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  222. //    Routine:        GetConversion
  223. //    Parameters:    none
  224. //    Returns:        A convert type value.
  225. //    Stores:        none
  226. //    Description:
  227. //        Returns the current value of the font conversion value to the caller.
  228. //    Bugs
  229. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  230. - (ConvertTypes) GetConversion
  231. {
  232.     return Convert;
  233. }
  234.  
  235.  
  236. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  237. //    Routine:        SetName:
  238. //    Parameters:    An enumerated value
  239. //    Returns:        self
  240. //    Stores:        none
  241. //    Description:
  242. //        When called, this will set the name of the font to the specified string.  This does
  243. //        make a copy of the string in the process. 
  244. //    Bugs
  245. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  246. - SetName: (CString) TheName
  247. {
  248.     FreeCString(FontName);
  249.     FontName = NewCString(strlen(TheName));
  250.     strcpy(FontName, TheName);
  251.     return self;
  252. }
  253.  
  254.  
  255. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  256. //    Routine:        GetName
  257. //    Parameters:    none
  258. //    Returns:        self
  259. //    Stores:        none
  260. //    Description:
  261. //        Returns a copy of the string of the name of the font.
  262. //    Bugs
  263. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  264. - (CString) GetName
  265. {
  266.     CString    temp    = NewCString(strlen(FontName));
  267.     
  268.     strcpy(temp, FontName);
  269.     return temp;
  270. }
  271.  
  272.  
  273. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  274. //    Routine:        AppendToName:
  275. //    Parameters:    A CString
  276. //    Returns:        self
  277. //    Stores:        none
  278. //    Description:
  279. //        This takes a string, and appends it to the font name we have so far.
  280. //    Bugs
  281. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  282. - AppendToName: (CString) TheName
  283. {
  284.     CString    temp = NewCString(strlen(FontName) + strlen(TheName));
  285.     
  286.     strcpy(temp,  FontName);
  287.     strcat(temp, TheName);
  288.     FreeCString(FontName);
  289.     FontName = temp;
  290.  
  291.     return self;
  292. }
  293.  
  294.  
  295. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  296. //    Routine:        PrepName
  297. //    Parameters:    none
  298. //    Returns:        self
  299. //    Stores:        none
  300. //    Description:
  301. //        This removes trailing semicolons, if any, and then removes leading and trailing
  302. //        spaces in the font's name
  303. //    Bugs
  304. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  305. - PrepName
  306. {
  307.     Integer    location = strlen(FontName) - 1;
  308.     Integer    newlocation;
  309.     //
  310.     //    First, back up past any trailing spaces and semicolons, and then 'null them out'
  311.     //
  312.     if ((FontName[location] == ' ') || (FontName[location] == ';'))
  313.         location--;
  314.     FontName[location+1] = EndOfCString;
  315.     //
  316.     //    Second, start copying characters, from start to end, over leading spaces, if any.
  317.     //
  318.     location = 0;
  319.     while (FontName[location] == ' ')
  320.         location++;
  321.     
  322.     if (location != 0)
  323.     {
  324.         newlocation = 0;
  325.         while (FontName[location] != EndOfCString)
  326.         {
  327.             FontName[newlocation] = FontName[location];
  328.             location++;
  329.             newlocation++;
  330.         }
  331.         FontName[newlocation] = EndOfCString;
  332.     }
  333.  
  334.     return self;
  335. }
  336.  
  337. @end
  338.